package com.cskaoyan.market.service;

import com.cskaoyan.market.db.domain.MarketCollect;
import com.cskaoyan.market.db.domain.MarketCollectExample;
import com.cskaoyan.market.db.mapper.MarketCollectMapper;
import com.cskaoyan.market.util.MybatisUtils;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author: YaLiFeng
 * @description: TODO
 * @date: 2024/5/7 10:47
 */
public class MarketCollectServiceImpl implements MarketCollectService {
    @Override
    public List<MarketCollect> list(Integer page, Integer limit, String sort, String order, String userId, String goodId) {
        SqlSession session= MybatisUtils.getSession();
        MarketCollectMapper mapper=session.getMapper(MarketCollectMapper.class);
        MarketCollectExample marketCollectExample=new MarketCollectExample();
        marketCollectExample.setOrderByClause(sort+" "+order);
        MarketCollectExample.Criteria criteria= marketCollectExample.createCriteria();
        if(!StringUtils.isEmpty(userId)){
            criteria.andUserIdEqualTo(Integer.valueOf(userId));
        }
        if(!StringUtils.isEmpty(goodId)){
            criteria.andValueIdEqualTo(Integer.valueOf(goodId));
        }
        criteria.andLogicalDeleted(true);
        PageHelper.startPage(page,limit);
        List<MarketCollect> marketCollects=mapper.selectByExampleSelective(marketCollectExample,MarketCollect.Column.id, MarketCollect.Column.userId, MarketCollect.Column.valueId,MarketCollect.Column.addTime,MarketCollect.Column.type,MarketCollect.Column.deleted);
        session.commit();
        session.close();
        return marketCollects;
    }
}
